<?php

class Listener_Order_Refunded_Qywx extends Listener_Base
{

    public function handle($args)
    {
        $self       = new self();
        $self->args = $args;
        //判断队列是否开启,如果开启则把任务推送到队列
        if ($self->queue_status) {
            Queue::in('default', Listener_Order_Refunded_Qywx::class, $args);
        } else {
            $self->perform();
        }
    }

    /**
     * 队列任务
     * @return void
     */
    public function perform()
    {
        $args       = $this->args;
        $ordersn    = $args['ordersn'];

        $order  = DB::select()
            ->from('member_order')
            ->where('ordersn', '=', $ordersn)
            ->execute()
            ->current();

        if ($order) {
            $result = St_QywxService::send_product_order_qywx(St_NoticeCommon::PRODUCT_ORDER_REFUND_MSGTAG, $order);
            St_Log::write('企业微信', array('ordersn' => $ordersn, 'result' => $result), 'event/order_refunded/log');
        }

    }

}